using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NTTHAO.Imaging;

public partial class admin_ImageProvider : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        NTTHAO.CommonWeb.LanguageUtility.ReloadLanguage(Request, Response, Session);

        try
        {
            Response.CacheControl = "public";
            Response.ContentType = "image/jpeg";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");

            string imgURL = Request.Params["imgurl"];
            if (imgURL == null || !System.IO.File.Exists(Server.MapPath(".." + (imgURL.Trim()[0] == '/' ? "" : "/") + imgURL)))
            {
                imgURL = "../resources/images/noimage.jpg";
            }

            imgURL = imgURL.Trim();

            string imgPath = Server.MapPath(".." + (imgURL[0] == '/' ? "" : "/") + imgURL);

            if (System.IO.File.Exists(imgPath))
            {
                if (ImageUtilities.GetImageFormat(imgPath) != null)
                {
                    System.Drawing.Image img = ImageUtilities.FromFile(imgPath);
                    System.Drawing.Image imgFixed = ImageUtilities.MaximumSizeFit(img, 100, 100);

                    ImageUtilities.SaveToJpegFile(imgFixed, Response.OutputStream, ImageUtilities.STANDARD_PROGRESSIVE);

                    img.Dispose();
                    imgFixed.Dispose();
                }
                else
                {
                    Response.Redirect(imgURL, false);
                }
            }
        }
        catch (Exception) { }
    }
}
